/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.modules.third.jg.report.information.thrift;

import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransportException;
import org.junit.After;
import org.junit.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 在这里编写类的功能描述
 *
 * @author duanlikao
 * @created 2021/1/20
 */
@Service
public class ReportPlatformClient {
    private static final Logger LOGGER = LoggerFactory.getLogger(ReportPlatformClient.class);

    private  ReportService.Client reportService;
    //二进制协议
    private TBinaryProtocol protocol;
    private TSocket transport;
    private String host = "192.168.0.254";
    private int port = 7099;
    public String getHost() {
        return host;
    }
    public void setHost(String host) {
        this.host = host;
    }
    public int getPort() {
        return port;
    }
    public void setPort(int port) {
        this.port = port;
    }

    @Before
    public void init() throws TException {
        transport = new TSocket(host, port);
        open();
        transport.setSocketTimeout(16000);
        protocol = new TBinaryProtocol(transport);
        reportService = new ReportService.Client(protocol);

    }

    public ReportService.Client getReportService() {
        return reportService;
    }

    public  void  open() {
        try {
            transport.open();
        } catch (TTransportException e) {
            LOGGER.info("ReportPlatformClient init open TTransportException : {}" ,e.getMessage());
        }
    }
    @After
    public  void  close()
    {
        transport.close();
    }
}